package de.baumann.browser.fragments


import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.adapter.PagerAdapter
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import kotlinx.android.synthetic.main.fragment_hash_order.*


/**
 *@author:
 *@date:2019/7/4 19:55
 *@discription: 算力包订单
 */
class HashOrderFragment : BaseOdinFragment<IBaseView, BasePresenter<IBaseView>>() {

    companion object {
        val instance: HashOrderFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            HashOrderFragment()
        }
    }

    override fun getLayout(): Int {
        return R.layout.fragment_hash_order
    }

    override fun initView(view: View) {
        rgHashOrder.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                R.id.rbHashOrderUnpaid -> {
                    vpHashOrder.currentItem = 0
                }

                R.id.rbHashOrderCompleted -> {
                    vpHashOrder.currentItem = 1
                }
            }
        }

        val fragments = arrayListOf<Fragment>(HashOrderUnpaidFragment.instance, HashOrderCompletedFragment.instance)
        vpHashOrder.adapter = PagerAdapter(childFragmentManager, fragments, null)
        vpHashOrder.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageSelected(position: Int) {
                when (position) {
                    0 -> rbHashOrderUnpaid.isChecked = true
                    1 -> rbHashOrderCompleted.isChecked = true
                }
            }

            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }
        })
    }

    override fun initData() {
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

}
